package cn.kkcxy.blog.server.controller.client;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.kkcxy.blog.core.dto.client.ClientPortalDTO;
import cn.kkcxy.blog.core.result.ResponseEntity;
import cn.kkcxy.blog.core.vo.client.ClientPortalVO;
import cn.kkcxy.blog.core.vo.client.ClientProfileVO;
import cn.kkcxy.blog.core.vo.client.archive.category.ClientCommonArticleCategoryVO;
import cn.kkcxy.blog.core.vo.client.archive.tag.ClientArticleTagsInfoVO;
import cn.kkcxy.blog.core.exception.article.ArticleServiceException;
import cn.kkcxy.blog.core.exception.base.BaseException;
import cn.kkcxy.blog.system.service.PortalService;
import com.alibaba.fastjson.JSON;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @BelongsProject: kkcxy-blog
 * @BelongsPackage: cn.kkcxy.blog.server.controller
 * @Author: kkcxy
 * @CreateTime: 2024-09-13 02:33
 * @Description: Client/Portal - controller
 * @Version: 1.0
 */
@Tag(name = "用户端-首页模块 Controller")
@Slf4j
@RestController
@RequestMapping("/client/portal")
public class PortalController {

    /**
     * Portal Service
     */
    @Resource
    private PortalService portalService;

    /**
     * @description: [用户端] 获取首页数据
     * @author: kkcxy
     * @date: 2024/9/13 23:13
     * @param: [clientPortalDTO]
     * @return: cn.kkcxy.blog.core.result.ResponseEntity<cn.kkcxy.blog.core.vo.client.ClientPortalVO>
     **/
    @SaIgnore
    @PostMapping("/info")
    @Operation(summary = "[用户端] 获取首页数据")
    public ResponseEntity<ClientPortalVO> getPortalInfo(@RequestBody ClientPortalDTO clientPortalDTO) {
        log.info("[用户端] 获取首页数据 请求参数: {}", JSON.toJSONString(clientPortalDTO));
        return ResponseEntity.success(new ClientPortalVO());
    }

    /**
     * @description: [用户端] 获取文章分类数据
     * @author: kkcxy
     * @date: 2024/9/26 22:03
     * @param: []
     * @return: java.util.List<cn.kkcxy.blog.core.vo.client.archive.category.ClientSecondLevelArticleCategoryVO>
     **/
    @SaIgnore
    @GetMapping("/common/categories")
    @Operation(summary = "[用户端] 获取文章分类数据")
    public ResponseEntity<List<ClientCommonArticleCategoryVO>> getArticleCategories() {
        try {
            log.info("获取文章分类数据");
            return ResponseEntity.success(portalService.getArticleCategories());
        } catch (ArticleServiceException exception) {
            log.error("[用户端] 获取文章分类数据 [ERROR]: {}", exception.getMessage(), exception);
            return ResponseEntity.fail(exception.getMessage());
        }
    }

    /**
     * @description: [用户端] 获取文章标签数据
     * @author: kkcxy
     * @date: 2024/9/26 22:03
     * @param: []
     * @return: java.util.List<cn.kkcxy.blog.core.vo.client.archive.tag.ClientArticleTagsInfoVO>
     **/
    @SaIgnore
    @GetMapping("/common/tags")
    @Operation(summary = "[用户端] 获取文章标签数据")
    public ResponseEntity<List<ClientArticleTagsInfoVO>> getArticleTags() {
        try {
            log.info("获取文章标签数据");
            return ResponseEntity.success(portalService.getArticleTags());
        } catch (ArticleServiceException exception) {
            log.error("[用户端] 获取文章标签数据 [ERROR]: {}", exception.getMessage(), exception);
            return ResponseEntity.fail(exception.getMessage());
        }
    }

    /**
     * @description: [用户端] 获取网站详情数据
     * @author: kkcxy
     * @date: 2024/9/28 22:43
     * @param: []
     * @return: cn.kkcxy.blog.core.result.ResponseEntity<cn.kkcxy.blog.core.vo.client.ClientProfileVO>
     **/
    @SaIgnore
    @GetMapping("/profile")
    @Operation(summary = "[用户端] 获取网站详情数据")
    public ResponseEntity<ClientProfileVO> getProfile() {
        try {
            log.info("获取网站详情数据");
            return ResponseEntity.success(portalService.getProfile());
        } catch (BaseException e) {
            log.error("[用户端] 获取网站详情数据 [ERROR]: {}", e.getMessage(), e);
            return ResponseEntity.fail(e.getMessage());
        }
    }
}
